<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录注册</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"
    integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
    crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.8/layui.js"
    integrity="sha512-wr2CJEbfG2lCok8dbfh12ZK76eVe0/4XRacTqUi+G1b77x+SpbVyMGn6nf0mWyvEuOAp2TfpMuq6U8fob09xgA=="
    crossorigin="anonymous" referrerpolicy="no-referrer"></script>

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.9.8/css/layui.css"
    integrity="sha512-rS4sRT9gLRT9wNIcmJPoU7+DI1vteqW3Bm51AlhupZ6JUxMYLhk4dKeL7y2rPBsi3JKth+Oz/BNvNjQAnpWdiw=="
    crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>

<body>

  <div class="login-page">
    <div class="form">
      <form class="layui-form" id="login-form" action="" lay-filter="testform" style="text-align: center;margin-right: 500px;margin-left: 500px;margin-top: 260px;">
        <h1>党务信息管理</h1>
        <div class="layui-form-item">
             <label class="layui-form-label">账号</label>
             <div class="layui-input-block">
               <input type="text" name="username" id="username" value="" required  lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input">
             </div>
        </div>
        <div class="layui-form-item">
             <label class="layui-form-label">密码</label>
             <div class="layui-input-block">
               <input type="text" name="password" value="" id="password" required  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
             </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">登录</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <a href="/register">没有账号？点我注册</a>
          </div>
        </div>
      </form>
    </div>
  </div>
</body>
<script>

  $("#login-form").submit(function (event) {
    event.preventDefault();
    $.post('/user', {
      account: $('#username').val(),
      password: $('#password').val()
    }, function (data) {
      console.log(data);
      if (data.code === 200) {

        layer.msg('验证通过');
        setTimeout(() => {
          window.location.href = "/index"
        }, 1000);
      } else {
        layer.msg('账号或者密码错误！');
      }
    })
  })
</script>

</html>